﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Gallio.Framework;
using MbUnit.Framework;
using MbUnit.Framework.ContractVerifiers;
using PTP.TestUtil; //extension methods

namespace PTP.Core
{
  [TestFixture]
  public class DebugUtilTest
  {
    [Test]
    [Row(0x00000000, "0")]
    [Row(0x00000001, "1")]
    [Row(0x000000FF, "FF")]
    [Row(0x00000100, "100")]
    [Row(0xFFFFFFFF, "FFFFFFFF")]
    [Row(0x89ABCDEF, "89ABCDEF")]
    public void ToHexDigits(uint val, string result)
    {
      Assert.AreEqual<string>(result, DebugUtil.ToHexDigits(val));
    }

    [Test]
    [Row(new byte[] { 0x00 }, "00")]
    [Row(new byte[] { 0x01 }, "01")]
    [Row(new byte[] { 0x13 }, "13")]
    [Row(new byte[] { 0xff }, "FF")]
    [Row(new byte[] { 0x00, 0x00 }, "00 00")]
    [Row(new byte[] { 0x01, 0x00 }, "01 00")]
    [Row(new byte[] { 0x01, 0x01 }, "01 01")]
    [Row(new byte[] { 0x01, 0xff }, "01 FF")]
    [Row(new byte[] { 0x13, 0x01, 0x00, 0x00, 0x12, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00 }, "13 01 00 00 12 00 01 80 00 00 00 00")]
    public void ToHexDigits_ByteArray(byte[] val, string result)
    {
      Assert.AreEqual<string>(result, DebugUtil.ToHexDigits(val, 0, val.Length));
    }

    [Test]
    public void ToHexDigits_TestHeader()
    {
      byte[] bytes = new byte[12];
      ContainerHeader h = new ContainerHeader();
      h.ContainerType = ContainerType.DataBlock;
      h.Code = (int)CommandCode.GetDeviceInfo;
      h.Length = 355;
      h.WriteBytes(bytes);
      Assert.AreEqual<string>("63 01 00 00 02 00 01 10 00 00 00 00", DebugUtil.ToHexDigits(bytes, 0, bytes.Length));
    }
    
  }
}
